package client.gameplay;

import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;

/**
 * Chat class
 */

public class Chat {
	public static final int TEXT_INLINE_X = 15;
	public static final int TEXTHEIGHT = 15;

	// time to display the chat-message in ms
	private static final int DISPLAY_MESSAGE_TIME = 5000;
	Map<Long, String> messages;
	
	

	public Chat() {
		messages = Collections.synchronizedMap(new TreeMap<Long, String>());
	}

	public void addMessage(String message) {
		messages.put(System.currentTimeMillis(),message);
			//messages.put(System.currentTimeMillis(), message);
	}

	public void updateChat() {
			Iterator<Long> itr = messages.keySet().iterator();
			while (itr.hasNext()) {
				Long key = itr.next();
				if (key + DISPLAY_MESSAGE_TIME < System.currentTimeMillis())
					itr.remove();
		}
	}

	public Collection<String> getMessages() {
			return messages.values();
	}

}
